a = int(input())
def is_prime(num):
  if num < 2:
    return False
  for i in range(2, int(num**0.5) + 1):
    if num % i == 0:
      return False
  return True
def big_prime(num):
  if len(str(a)) != 4:
    return 0
  chisla = list(str(num))
  big_num = 0
  for i in range(len(chisla)):
    for j in range(i, len(chisla)):
      if i == j:
        wr_num = int(chisla[i])
      else:
        wr_num = int(''.join(chisla[i:j+1]))
      if is_prime(wr_num) and wr_num > big_num:
        big_num = wr_num
  return big_num
print(big_prime(a))